#define _CRT_SECURE_NO_WARNINGS 1




#include <stdio.h>


void swap(void* p1, void* p2, int size)
{
	char tmp;
	for (int i = 0; i < size; ++i)
	{
		tmp = *((char*)p1 + i);
		*((char*)p1 + i) = *((char*)p2 + i);
		*((char*)p2 + i) = tmp;
	}
}

void Busort(void* base, int count, int size, int (*cmp)(void*,void*))
{
	for (int i = 0; i < count - 1; ++i)
	{
		for (int j = 0; j < count - i - 1; ++j)
		{
			if (cmp((char*)base + j * size, (char*)base + (j + 1) * size) > 0)
			{
				swap((char*)base + j * size, (char*)base + (j + 1) * size, size);
			}
		}
	}


}


int int_cmp(const void* p1, const void* p2)
{
	return (*(int*)p1) - (*(int*)p2);
}

int char_cmp(const void* p1, const void* p2)
{
	return(*(char*)p1) - (*(char*)p2);
}

int main()
{
	int a[10] = { 1,5,2,3,6,3,7,2,4,9 };
	char b[10] = { 'a','p','c','b','d','f','e','o','j','k' };
	Busort(a,sizeof(a)/sizeof(a[0]),sizeof(int),int_cmp);
	Busort(b, sizeof(b) / sizeof(b[0]), sizeof(char), char_cmp);
	for (int i = 0; i < 10; ++i)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
	for (int i = 0; i < 10; ++i)
	{
		printf("%c ", b[i]);
	}
	printf("\n");
	return 0;
}